package com.linchong.jvm.gc;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2020-11-18 23:08
 * @Description: HelpSelf$对象自救
 */
public class HelpSelf {

	private static HelpSelf hs = null;

	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		System.out.println("now in finalize==");
		// 对象自救
		hs = this;
	}

	public static void main(String[] args) throws InterruptedException {
		hs = new HelpSelf();

		// 第一次
		hs = null;
		System.gc();
		Thread.sleep(1_000);
		System.out.println("first hs==="+hs);

		// 第二次
		hs = null;

		Thread.sleep(1_000);
		System.out.println("second hs==="+hs);
	}
}
